//
//  DYEnterShopView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/11.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYEnterShopView.h"

@interface DYEnterShopView ()

@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)DYEnterShopChildView *nameView;
@property (nonatomic,strong)DYEnterShopChildView *industryView;
@property (nonatomic,strong)DYEnterShopChildView *addressView;
@property (nonatomic,strong)DYEnterShopChildView *detailAddressView;

@property (nonatomic,strong)UIButton *openButton;
@property (nonatomic,strong)UILabel *agreementLabel;
@property (nonatomic,strong)UIButton *agreementButton;

@end


@implementation DYEnterShopView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{
    self.scrollView= ({
        UIScrollView *scrollView=[[UIScrollView alloc]init];
        scrollView;
    });
    
    self.nameView = ({
        
        DYEnterShopChildView *view=[[DYEnterShopChildView alloc]init];
        view.titleStr=@"店铺名称";
        view.placeHolder=@"请输入店铺名称";
        view;
    });
    
    self.industryView = ({
       
        DYEnterShopChildView *view=[[DYEnterShopChildView alloc]init];
        view.titleStr=@"行业";
        view.placeHolder=@"请选择行业";
        view.isShow=YES;
        view;
        
    });
    
    self.addressView = ({
        
        DYEnterShopChildView *view=[[DYEnterShopChildView alloc]init];
        view.titleStr=@"店铺地址";
        view.placeHolder=@"请选择店铺省份";
        view.isShow=YES;
        view;
    });
    
    self.detailAddressView = ({
        
        DYEnterShopChildView *view=[[DYEnterShopChildView alloc]init];
        view.titleStr=@"详细地址";
        view.placeHolder=@"请输入详细地址";
        view;
        
    });
    
    self.openButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:[UIColor xhq_base] action:@selector(buttonClick:) target:self title:@"开店" image:@"icon_login" font:17 textColor:WhiteColor];
        [button xhq_cornerRadius:BILIHEIGHT(19)];
        button;
    });
    
    self.agreementLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:[UIColor xhq_content] alignment:0];
        label.text=@"开店即表示同意";
        label;
    });
    
    self.agreementButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:[UIColor whiteColor] action:@selector(buttonClick:) target:self title:@"《入驻协议》" image:nil font:14 textColor:[UIColor xhq_base]];
        button;
    });
    
    [self addSubview:self.scrollView];
    
    [self.scrollView addSubview:self.nameView];
    [self.scrollView addSubview:self.industryView];
    [self.scrollView addSubview:self.addressView];
    [self.scrollView addSubview:self.detailAddressView];
    
    
    [self addSubview:self.openButton];
    [self addSubview:self.agreementLabel];
    [self addSubview:self.agreementButton];
 
    [self.scrollView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(0);
    }];
    
    [self.nameView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(10));
        make.top.equalTo(BILIHEIGHT(14));
        make.size.equalTo(CGSizeMake(kScreenWidth-BILIWIDTH(20), BILIHEIGHT(50)));
    }];

    [self.industryView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.nameView);
        make.top.equalTo(self.nameView.bottom).offset(BILIHEIGHT(8));
    }];

    [self.addressView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.nameView);
        make.top.equalTo(self.industryView.bottom).offset(BILIHEIGHT(8));
    }];

    [self.detailAddressView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.nameView);
        make.top.equalTo(self.addressView.bottom).offset(BILIHEIGHT(8));
    }];
    
   
    [self.openButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(BILIWIDTH(-10));
        make.top.equalTo(self.detailAddressView.bottom).offset(BILIHEIGHT(30));
        make.size.equalTo(CGSizeMake(BILIWIDTH(98), BILIHEIGHT(38)));
    }];
    
    
    [self.agreementLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(BILIHEIGHT(-45));
        make.centerX.equalTo(self).offset(BILIWIDTH(-40));
    }];

    [self.agreementButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.agreementLabel);
        make.left.equalTo(self.agreementLabel.right).offset(BILIWIDTH(0));
    }];
    
    [self.openButton placeImageTitlePosition:ZYButtonImagePositionRight space:BILIWIDTH(5)];
    
    
    self.industryView.block = ^{
      XHQHUDTEXT(@"选择行业");
    };
    
    self.addressView.block = ^{
        XHQHUDTEXT(@"选择城市");
    };
    
}
-(void)buttonClick:(UIButton *)button
{
    if (self.enterShopBlock) {
        if (button==self.openButton) {
            self.enterShopBlock(1);
        }else if (button==self.agreementButton){
            self.enterShopBlock(2);
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end



@interface DYEnterShopChildView ()

@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UITextField *textField;
@property (nonatomic,strong)UILabel *line;
@property (nonatomic,strong)UIButton *seletedButton;
@property (nonatomic,strong)UIButton *textButton;

@end

@implementation DYEnterShopChildView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{

    self.titleLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:12 textColor:[UIColor xhq_content] alignment:0];
        label;
    });
    
    self.textField = ({
        UITextField *text=[[UITextField alloc]init];
        text.font=kFont(14);
        text;
    });
    
    self.line = ({
        UILabel *label=[UILabel xhq_lineLabel];
        label.backgroundColor=LoginLineColor;
        label;
    });
    
    self.seletedButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(seletedButtonClick) target:self title:nil image:@"icon_select" font:12 textColor:WhiteColor];
        button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
        button.hidden=YES;
        button;
    });
    
    self.textButton = ({
        
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(seletedButtonClick) target:self title:nil image:nil font:14 textColor:[UIColor xhq_assist]];
        button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        button.hidden=YES;
        button;
    });
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.textField];
    [self addSubview:self.line];
    [self addSubview:self.seletedButton];
    [self addSubview:self.textButton];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.top.equalTo(BILIHEIGHT(0));
    }];

    [self.textField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.width.equalTo(kScreenWidth-BILIWIDTH(20));
        make.height.equalTo(BILIHEIGHT(30));
        make.bottom.equalTo(BILIHEIGHT(-1));
    }];
    
    [self.textButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
//        make.width.equalTo(kScreenWidth-BILIWIDTH(20));
        make.height.equalTo(BILIHEIGHT(30));
        make.bottom.equalTo(BILIHEIGHT(-1));
    }];

    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.width.equalTo(self.textField);
        make.bottom.equalTo(0);
        make.height.equalTo(BILIWIDTH(0.7));
    }];

    [self.seletedButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(0);
        make.size.equalTo(CGSizeMake(BILIWIDTH(40), BILIHEIGHT(50)));
    }];
}
-(void)seletedButtonClick
{
    !self.block ?: self.block();
}
-(void)setIsShow:(BOOL)isShow
{
    _isShow=isShow;
     self.seletedButton.hidden=!isShow;
    self.textButton.hidden=!isShow;
    
    if (self.isShow) {
        self.textField.hidden=YES;
    }
}
-(void)setTitleStr:(NSString *)titleStr
{
    _titleStr=titleStr;
    self.titleLabel.text=titleStr;
}
-(void)setPlaceHolder:(NSString *)placeHolder
{
    _placeHolder=placeHolder;
    self.textField.placeholder=placeHolder;
    [self.textField setValue:[UIColor xhq_assist] forKeyPath:@"_placeholderLabel.textColor"];
    
    [self.textButton setTitle:placeHolder forState:UIControlStateNormal];
    
}

@end


